import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { resolve } from "node:path";
import copy from "rollup-plugin-copy";

// https://vite.dev/config/
export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      "@": resolve(__dirname, "./plugin"),
      "@com": resolve(__dirname, "./plugin/components"),
      "@u": resolve(__dirname, "./plugin/utils"),
    },
  },
  // 打包配置
  build: {
    //配置库模式打包
    lib: {
      entry: "plugin/index.ts", // 设置入口文件
      name: "hsw-component-hooks-vue", // 起个名字，安装、引入用
      fileName: (format) => `hsw-component-hooks-vue.${format}.js`, // 打包后的文件名
    },
    sourcemap: true, // 输出.map文件
    rollupOptions: {
      // 确保外部化处理那些你不想打包进库的依赖
      external: ["vue", "element-plus"],
      output: {
        // 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量
        globals: {
          vue: "Vue",
          "element-plus": "element-plus",
        },
      },
      plugins: [
        // copy({
        //   targets: [
        //     { src: "public/hsw-component-hooks-vue.d.ts", dest: "dist" },
        //   ],
        // }),
      ],
    },
  },
  css: {
    preprocessorOptions: {
      less: {
        javascriptEnabled: true,
        //引入公共css样式
        // additionalData: '@import "./src/packages/index.less";',
      },
    },
  },
});
